package _2021;

import java.util.HashSet;
import java.util.Set;

/**
 * @author ShadowLim
 * @create 2022-03-29-16:48
 */
public class 直线 {
    static Set<String> ans = new HashSet<>();

    public static void main(String[] args) {
        for (int x1 = 0; x1 < 20; x1++) {
            for (int y1 = 0; y1 < 21; y1++) {
                for (int x2 = 0; x2 < 20; x2++) {
                    for (int y2 = 0; y2 < 21; y2++) {
                        // 斜率不存在/斜率为 0
                        if (x1 == x2 || y1 == y2) {
                            continue;
                        }
                        // 以分子分母形式表示斜率和截距时 分子分母要最简
                        StringBuilder sb = new StringBuilder();
                        /** 求斜率： y = up/down * x + b
                         *  y1 = up/down * x + b1   y2 = up/down * x + b2
                         *  up = y2 - y1  down = x2 - x1
                         */
                        int up = y2 - y1, down = x2 - x1;   // 斜率k的分子分母
                        int maxConvention = gcd(up, down);
                        sb.append(up / maxConvention + "/" + down / maxConvention + " ");
                        /** 求截距： y = up/down * x + b
                         *  y * down = up * x + b * down
                         *  b = (y*down - up*x) / down
                         *  同样地,截距以分子分母形式表示时 分子分母要最简
                         *  r = gcd(y*down - up*x, down)
                         *  最终 截距b的最简形式：(up / r) / (down / r)
                         */
                        up = y1 * down - x1 * up;   // 更新截距分子
                        maxConvention = gcd(up, down); // 更新最大公约数
                        sb.append(up / maxConvention + " " + down / maxConvention);
                        ans.add(sb.toString());
                    }
                }
            }
        }
        // 斜率不存在的直线有20根 斜率为0的直线有21根
        System.out.println(ans.size() + 20 + 21);
    }

    private static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    /** 砝码数量       可选到的重量
     *    1             1
     *    2             1 2(3-1：天平左右放1和3) 3 4(1+3)
     *    3             5(1+2+2) 6(2+2+2) 7() 8() 9() 10() 11() 12() 13()
     *    4             14~40
     */
}

